#!/bin/bash

source /home/shell/util.sh

function install () {
    lastversion=`curl -sL https://nodejs.org/dist/latest-v17.x/|perl -pe "s/.*href=\"(.*)\".*/\1/g"|grep "linux-x64.tar.gz"`;
    download /opt/node-latest.tar.gz https://nodejs.org/dist/latest-v17.x/${lastversion}
    tar -zxf /opt/node-latest.tar.gz -C /opt
    rm -rf /opt/node-latest.tar.gz
    mv /opt/node-v* /opt/nodejs
}

function config () {
tee /etc/profile.d/nodejs.sh<<EOF
export NODE_PATH="/opt/nodejs"
export PATH="\$NODE_PATH/bin:\$PATH"
EOF
    source /etc/profile.d/nodejs.sh
    npm config set registry https://registry.npm.taobao.org
    npm install cnpm -g --registry=https://registry.npm.taobao.org
}

function install_vue () {
    npm install vue -g
}


install && config

printInfo "====================安装信息===================="
printInfo "node version: `node -v`"
printInfo "npm version: `npm -v`"
printInfo "registry: `npm config get registry`"
printInfo "====================安装信息===================="